<html devsite>
  <head>
    <title>Install TensorFlow with pip</title>
    <meta name="project_path" value="/_project.yaml" />
    <meta name="book_path" value="/_book.yaml" />
    <link rel="stylesheet" href="/site-assets/css/style.css">
  </head>
  <body>

<h3>Available packages</h3>
<ul>
  <li><code>tensorflow</code> —Current release for CPU-only <em>(recommended for beginners)</em></li>
  <li><code>tensorflow-gpu</code> —Current release with <a href="./gpu">GPU support</a> <em>(Ubuntu and Windows)</em></li>
  <li><code>tf-nightly</code> —Nightly build for CPU-only <em>(unstable)</em></li>
  <li><code>tf-nightly-gpu</code> —Nightly build with <a href="./gpu">GPU support</a> <em>(unstable, Ubuntu and Windows)</em></li>
</ul>

<h3>System requirements</h3>
<ul>
  <li>Ubuntu 16.04 or later (64-bit)</li>
  <li>macOS 10.12.6 (Sierra) or later (64-bit) <em>(no GPU support)</em></li>
  <li>Windows 7 or later (64-bit) <em>(Python 3 only)</em></li>
  <li>Raspbian 9.0 or later</li>
</ul>

<h3>Hardware requirements</h3>
<ul>
  <li>Starting with TensorFlow 1.6, binaries use <a href="https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#CPUs_with_AVX" class="external">AVX instructions</a> which may not run on older CPUs.</li>
  <li>Read the <a href="./gpu">GPU support guide</a> to set up a CUDA®-enabled GPU card on Ubuntu or Windows.</li>
</ul>


<h2>1. Install the Python development environment on your system</h2>

<form>
  <input type="radio" class="devsite-navigating-radio" name="lang" value="python3" data-is-default>
  <label for="radio-python3">Python 3</label>
  <input type="radio" class="devsite-navigating-radio" name="lang" value="python2">
  <label for="radio-python2">Python 2.7</label>
</form>

<p>
  Check if your Python environment is already configured:
</p>

{% dynamic if request.query_string.lang == "python2" %}
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">python --version</code>
<code class="devsite-terminal">pip --version</code>
<code class="devsite-terminal">virtualenv --version</code>
</pre>
{% dynamic else %}<!-- python3 -->
<aside class="note">Requires Python 3.4, 3.5, or 3.6</aside>

<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">python3 --version</code>
<code class="devsite-terminal">pip3 --version</code>
<code class="devsite-terminal">virtualenv --version</code>
</pre>
{% dynamic endif %}

<p>
  If these packages are already installed, skip to the next step.<br/>
  Otherwise, install <a href="https://www.python.org/" class="external">Python</a>, the
  <a href="https://pip.pypa.io/en/stable/installing/" class="external">pip package manager</a>,
  and <a href="https://virtualenv.pypa.io/en/stable/" class="external">Virtualenv</a>:
</p>

{% dynamic if request.query_string.lang == "python2" %}

<div class="ds-selector-tabs">
<section>
<h3>Ubuntu</h3>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">sudo apt update</code>
<code class="devsite-terminal">sudo apt install python-dev python-pip</code>
<code class="devsite-terminal">sudo pip install -U virtualenv  # system-wide install</code>
</pre>
</section>

<section>
<h3>mac OS</h3>
<p>Install using the <a href="https://brew.sh/" class="external">Homebrew</a> package manager:</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</code>
<code class="devsite-terminal">export PATH="/usr/local/bin:/usr/local/sbin:$PATH"</code>
<code class="devsite-terminal">brew update</code>
<code class="devsite-terminal">brew install python@2  # Python 2</code>
<code class="devsite-terminal">sudo pip install -U virtualenv  # system-wide install</code>
</pre>
</section>

<section>
<h3>Raspberry Pi</h3>
<p>Requirements for the <a href="https://www.raspberrypi.org/downloads/raspbian/" class="external">Raspbian</a> operating system:</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">sudo apt update</code>
<code class="devsite-terminal">sudo apt install python-dev python-pip</code>
<code class="devsite-terminal">sudo apt install libatlas-base-dev     # required for numpy</code>
<code class="devsite-terminal">sudo pip install -U virtualenv         # system-wide install</code>
</pre>
</section>

<section>
<h3>Other</h3>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py</code>
<code class="devsite-terminal">python get-pip.py</code>
<code class="devsite-terminal">sudo pip install -U virtualenv  # system-wide install</code>
</pre>
</section>
</div><!--/ds-selector-tabs-->

{% dynamic else %}<!-- python3 -->

<div class="ds-selector-tabs">
<section>
<h3>Ubuntu</h3><!--python3-->
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">sudo apt update</code>
<code class="devsite-terminal">sudo apt install python3-dev python3-pip</code>
<code class="devsite-terminal">sudo pip3 install -U virtualenv  # system-wide install</code>
</pre>  
</section>

<section>
<h3>mac OS</h3><!--python3-->
<p>Install using the <a href="https://brew.sh/" class="external">Homebrew</a> package manager:</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</code>
<code class="devsite-terminal">export PATH="/usr/local/bin:/usr/local/sbin:$PATH"</code>
<code class="devsite-terminal">brew update</code>
<code class="devsite-terminal">brew install python  # Python 3</code>
<code class="devsite-terminal">sudo pip3 install -U virtualenv  # system-wide install</code>
</pre>
</section>

<section>
<h3>Windows</h3><!--python3-->
<p>
  Install the <em>Microsoft Visual C++ 2015 Redistributable Update 3</em>. This
  comes with <em>Visual Studio 2015</em> but can be installed separately:
</p>
<ol>
<li>Go to the <a href="https://visualstudio.microsoft.com/vs/older-downloads/" class="external">Visual Studio downloads</a>,</li>
<li>Select <em>Redistributables and Build Tools</em>,</li>
<li>Download and install the <em>Microsoft Visual C++ 2015 Redistributable Update 3</em>.</li>
</ol>
<p>Install the <em>64-bit</em> <a href="https://www.python.org/downloads/windows/" class="external">Python 3 release for Windows</a> (select <code>pip</code> as an optional feature).</p>
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">pip3 install -U pip virtualenv</pre>
</section>

<section>
<h3>Raspberry Pi</h3>
<p>Requirements for the <a href="https://www.raspberrypi.org/downloads/raspbian/" class="external">Raspbian</a> operating system:</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">sudo apt update</code>
<code class="devsite-terminal">sudo apt install python3-dev python3-pip</code>
<code class="devsite-terminal">sudo apt install libatlas-base-dev        # required for numpy</code>
<code class="devsite-terminal">sudo pip3 install -U virtualenv           # system-wide install</code>
</pre>
</section>

<section>
<h3>Other</h3><!--python3-->
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal">curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py</code>
<code class="devsite-terminal">python get-pip.py</code>
<code class="devsite-terminal">sudo pip3 install -U virtualenv  # system-wide install</code>
</pre>
</section>
</div><!--/ds-selector-tabs-->

{% dynamic endif %}


<h2>2. Create a virtual environment (recommended)</h2>

<p>
  Python virtual environments are used to isolate package installation from the system.
</p>

<div class="ds-selector-tabs">
<section>
<h3>Ubuntu / mac OS</h3>
<p>
  Create a new virtual environment by choosing a Python interpreter and making a
  <code>./venv</code> directory to hold it:
</p>
{% dynamic if request.query_string.lang == "python2" %}
<pre class="devsite-terminal devsite-click-to-copy">virtualenv --system-site-packages -p python2.7 <var>./venv</var></pre>
{% dynamic else %}
<pre class="devsite-terminal devsite-click-to-copy">virtualenv --system-site-packages -p python3 <var>./venv</var></pre>
{% dynamic endif %}
<p>
  Activate the virtual environment using a shell-specific command:
</p>
<pre class="devsite-terminal prettyprint lang-bsh">source <var>./venv</var>/bin/activate  # sh, bash, ksh, or zsh</pre>
<p>
  When virtualenv is active, your shell prompt is prefixed with <code>(venv)</code>.
</p>
<p>
  Install packages within a virtual environment without affecting the host system
  setup. Start by upgrading <code>pip</code>:
</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal tfo-terminal-venv">pip install --upgrade pip</code>

<code class="devsite-terminal tfo-terminal-venv">pip list  # show packages installed within the virtual environment</code>
</pre>
<p>
  And to exit virtualenv later:
</p>
<pre class="devsite-terminal tfo-terminal-venv prettyprint lang-bsh">deactivate  # don't exit until you're done using TensorFlow</pre>
</section>


<section>
  <h3>Windows</h3>
  <p>
  Create a new virtual environment by choosing a Python interpreter and making a
  <code>./venv</code> directory to hold it:
</p>
{% dynamic if request.query_string.lang == "python2" %}
<aside class="warning">TensorFlow is not supported on Windows with Python 2.7</aside>
{% dynamic else %}
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">virtualenv --system-site-packages -p python3 <var>./venv</var></pre>
{% dynamic endif %}
<p>
  Activate the virtual environment:
</p>
<pre class="devsite-terminal tfo-terminal-windows-venv"><var>.\venv</var>\Scripts\activate</pre>
<p>
  Install packages within a virtual environment without affecting the host system
  setup. Start by upgrading <code>pip</code>:
</p>
<pre class="prettyprint lang-bsh">
<code class="devsite-terminal tfo-terminal-windows-venv">pip install --upgrade pip</code>

<code class="devsite-terminal tfo-terminal-windows-venv">pip list  # show packages installed within the virtual environment</code>
</pre>
<p>
  And to exit virtualenv later:
</p>
<pre class="devsite-terminal tfo-terminal-windows-venv prettyprint lang-bsh">deactivate  # don't exit until you're done using TensorFlow</pre>
</section>


<section>
<h3>Conda</h3>
<aside class="note">
  While we recommend the TensorFlow-provided <em>pip</em> package, a
  <em>community-supported</em> <a href="https://anaconda.org/conda-forge/tensorflow" class="external">Anaconda package</a>
  is available.
</aside>
<p>
  Create a new virtual environment by choosing a Python interpreter and making a
  <code>./venv</code> directory to hold it:
</p>
{% dynamic if request.query_string.lang == "python2" %}
<pre class="devsite-terminal devsite-click-to-copy">conda create -n <var>venv</var> pip python=2.7</pre>
{% dynamic else %}
<pre class="devsite-terminal devsite-click-to-copy">conda create -n <var>venv</var> pip python=3.6  # select python version</pre>
{% dynamic endif %}
<p>Activate the virtual environment:</p>
<pre class="devsite-terminal devsite-click-to-copy">source activate <var>venv</var></pre>
<p>
  Within the virtual environment, install the TensorFlow pip package using its <a href="#package-location">complete URL</a>:
</p>
<pre class="devsite-terminal tfo-terminal-venv prettyprint lang-bsh">pip install --ignore-installed --upgrade <var>packageURL</var></pre>
<p>
  And to exit virtualenv later:
</p>
<pre class="devsite-terminal tfo-terminal-venv prettyprint lang-bsh">source deactivate</pre>
</section>
</div><!--/ds-selector-tabs-->


<h2>3. Install the TensorFlow pip package</h2>

<p>
  Choose one of the following TensorFlow packages to install <a href="https://pypi.org/project/tensorflow/" class="external">from PyPI</a>:
</p>

<ul>
  <li><code>tensorflow</code> —Current release for CPU-only <em>(recommended for beginners)</em></li>
  <li><code>tensorflow-gpu</code> —Current release with <a href="./gpu">GPU support</a> <em>(Ubuntu and Windows)</em></li>
  <li><code>tf-nightly</code> —Nightly build for CPU-only <em>(unstable)</em></li>
  <li><code>tf-nightly-gpu</code> —Nightly build with <a href="./gpu">GPU support</a> <em>(unstable, Ubuntu and Windows)</em></li>
</ul>

<aside class="note">
  Package dependencies are automatically installed. These are listed in the
  <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/pip_package/setup.py" class="external"><code>setup.py</code></a>
  file under <code>REQUIRED_PACKAGES</code>.
</aside>

<div class="ds-selector-tabs">
<section>
<h3>Virtualenv install</h3>
<pre class="devsite-terminal tfo-terminal-venv devsite-click-to-copy prettyprint lang-bsh">pip install --upgrade tensorflow</pre>
<p>Verify the install:</p>
<pre class="devsite-terminal tfo-terminal-venv devsite-click-to-copy prettyprint lang-bsh">python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"</pre>
</section>

<section>
<h3>System install</h3>
{% dynamic if request.query_string.lang == "python2" %}
<pre class="devsite-terminal devsite-click-to-copy prettyprint lang-bsh">pip install --user --upgrade tensorflow  # install in $HOME</pre>
<p>Verify the install:</p>
<pre class="devsite-terminal devsite-click-to-copy prettyprint lang-bsh">python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"</pre>
{% dynamic else %}<!--python3-->
<pre class="devsite-terminal devsite-click-to-copy prettyprint lang-bsh">pip3 install --user --upgrade tensorflow  # install in $HOME</pre>
<p>Verify the install:</p>
<pre class="devsite-terminal devsite-click-to-copy prettyprint lang-bsh">python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"</pre>
{% dynamic endif %}
</section>
</div><!--/ds-selector-tabs-->

<aside class="success"><b>Success:</b> TensorFlow is now installed. Read the <a href="../tutorials">tutorials</a> to get started.</aside>

<h2>Package location</h2>

<p>
  A few installation mechanisms require the URL of the TensorFlow Python package.
  The value you specify depends on your Python version.
</p>

<table>
  <tr><th>Version</th><th>URL</th></tr>
  <tr class="alt"><td colspan="2">Linux</td></tr>
  <tr>
    <td>Python 2.7 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp27-none-linux_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 2.7 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp27-none-linux_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.4 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp34-cp34m-linux_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.4 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp34-cp34m-linux_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.5 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.5 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp35-cp35m-linux_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.6 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl</td>
  </tr>
  <tr>
    <td>Python 3.6 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp36-cp36m-linux_x86_64.whl</td>
  </tr>

  <tr class="alt"><td colspan="2">macOS (CPU-only)</td></tr>
  <tr>
    <td>Python 2.7</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py2-none-any.whl</td>
  </tr>
  <tr>
    <td>Python 3.4, 3.5, 3.6</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl</td>
  </tr>

  <tr class="alt"><td colspan="2">Windows</td></tr>
  <tr>
    <td>Python 3.5 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp35-cp35m-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.5 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.12.0-cp35-cp35m-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.6 CPU-only</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp36-cp36m-win_amd64.whl</td>
  </tr>
  <tr>
    <td>Python 3.6 GPU&nbsp;support</td>
    <td class="devsite-click-to-copy">https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl</td>
  </tr>
</table>

</body>
</html>
